package com.zmn.oms.services.impl.perf;

import com.zmn.manager.common.database.annotation.ReadOnlyConnection;
import com.zmn.oms.model.entity.perf.PerfCity;
import com.zmn.oms.model.entity.perf.PerfCityQuery;
import com.zmn.oms.model.entity.perf.PerfCitySummary;
import com.zmn.oms.persistence.interfaces.perf.PerfCityDao;
import com.zmn.oms.services.interfaces.perf.PerfCityService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.Collections;
import java.util.List;
import java.util.Objects;

/**
 * 类描述: 城市绩效
 *
 * @author liuying
 * @date 2019/01/30 4:43 PM
 */
@Service
public class PerfCityServiceImpl implements PerfCityService {

    @Resource
    private PerfCityDao perfCityDao;

    @Override
    @ReadOnlyConnection
    public List<PerfCity> listPerfCity(PerfCityQuery perfCityQuery) {
        Integer count = perfCityDao.countPerfCity(perfCityQuery);
        perfCityQuery.setTotalCount(count);
        return count > 0 ? perfCityDao.listPerfCity(perfCityQuery) : Collections.emptyList();
    }

    @Override
    public void insertBatch(List<PerfCity> list) {
        perfCityDao.insertBatch(list);
    }

    @Override
    public int insert(PerfCity perfCity) {
        return perfCityDao.insert(perfCity);
    }

    @Override
    public void deletcByMonth(int month) {
        this.perfCityDao.deleteByDateSpan(month);
    }

    @Override
    @ReadOnlyConnection
    public PerfCitySummary findTotalLine(PerfCityQuery query) {
        PerfCitySummary totalLine = this.perfCityDao.findTotalLine(query);
        if (Objects.nonNull(totalLine)) {
            totalLine.setManageCompanyName("汇总");
        }
        return totalLine;
    }
}
